package com.hysf.ioc.pro2;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class App2 {
	public static void main(String[] args) {
		ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
		DataSource dataSource = context.getBean(DruidDataSource.class);
		// 测试连接
		try(Connection connection = dataSource.getConnection();) {
			if (connection != null) {
				System.out.println("连接成功");
			}
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
}
